require 'View/UIBase/UIBase'

UIFavorAward = UIBase.New(PanelNames.UIFavorAward);
local this=UIFavorAward
function this.Init(heroId)
    this.heroId=heroId
    this.heroData=logicMgr.HeroManager.getHeroDatabyModelId(this.heroId,true)
    UIBase.Init(this);
end

function this:OnCreate()
    self.btnClose=self:GetChild("bgClose")
    self.listReward=self:GetChild("root/elementGroup")
    self:addEvent();
end

function this:OnEnable()
    this:Refresh()
end

function this:OnDisable()

end

function this:OnDestroy()

end
-------------------------------function--------------------------------------
function this:OnClickClose()
    self:OnBack()
end

function this:addEvent()
    self:RegisterOnClick(self.btnClose,self.OnClickClose)
    self:SetDynamicList(self.listReward,self.SetRewardData)
end
function this:SetRewardData(index,obj)
    local data=self.rewardData[index]
    local ctrlType=obj:GetController("type")
    local ctrlState=obj:GetController("state")
    if data.f_FavorLevel>self.heroData.favorLv then
        ctrlState.selectedIndex=0
    else
        ctrlState.selectedIndex=1
    end
    local rewardList=obj:GetChild("rewardList")
    local txtTitle=obj:GetChild("title")

    if data.f_RewardType==3 then
        ctrlType.selectedIndex=1
        logicMgr.CostManager.RefreshItemList(rewardList,data.f_Reward)
    else
        ctrlType.selectedIndex=0
    end
    local language=getLanguage("HeroFavorReward"..data.f_RewardType)
    txtTitle.text=string.format(language,data.f_FavorLevel,data.f_RewardCo)
end
function this:Refresh()
    self.rewardData=logicMgr.HeroFavorManager.getRewardData(this.heroId)
    self.listReward.numItems=0
    self.listReward.numItems=#self.rewardData
end

return this